package com.ds.plugins;

import com.ds.common.JDSException;
import com.ds.config.ListResultModel;
import com.ds.esd.annotation.field.APIEventAnnotation;
import com.ds.esd.annotation.ui.ComponentType;
import com.ds.esd.annotation.ui.RequestPathEnum;
import com.ds.esd.annotation.ui.ResponsePathEnum;
import com.ds.esd.tool.component.ComboInputComponent;
import com.ds.esd.tool.component.Component;
import com.ds.esd.tool.component.ModuleComponent;
import com.ds.esd.tool.properties.form.ComboInputProperties;
import com.ds.test.TestView;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;
@Controller
@RequestMapping(value = "/eidtor/")
public class EditorService {
    @RequestMapping(value = "onChange")
    @APIEventAnnotation(customResponseData = ResponsePathEnum.EXPRESSION, customRequestData = RequestPathEnum.CURRFORM)
    @ResponseBody
    public ListResultModel<List<Component>> onChange(@RequestBody TestView testView, ModuleComponent moduleComponent) {
        ListResultModel<List<Component>> listResultModel = new ListResultModel();
        List<Component> components = new ArrayList<>();
        List<ComboInputComponent> comboInputComponents = null;
        try {
            comboInputComponents = moduleComponent.getRealModuleComponent().findComponents(ComponentType.COMBOINPUT, null);
            ((ComboInputProperties) comboInputComponents.get(1).getProperties()).setDisabled(true);
            ((ComboInputProperties) comboInputComponents.get(1).getProperties()).setValue(14);
            components.addAll(comboInputComponents);
        } catch (JDSException e) {
            e.printStackTrace();
        }
        listResultModel.setData(components);
        return listResultModel;
    }

}
